package cn.edkuir.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要的数据
 */
@ToString
public class OrderConfirmVo {

    //收货地址
    @Setter @Getter
    private List<MemberAddressVo> addressList;

    //所有选中的购物项
    @Setter @Getter
    private List<OrderItemVo> items;

    //每个sku对应是否有库存
    @Getter @Setter
    private Map<Long, Boolean> stocks;

    //优惠券信息(积分)
    @Setter @Getter
    private Integer integration;

    //订单总额
    private BigDecimal total;

    //应付价格
    private BigDecimal payPrice;

    //防重令牌
    @Setter @Getter
    private String orderToken;


    public Integer getCount() {
        Integer count = 0;
        if(items != null) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }


    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if(items != null) {
            for (OrderItemVo item : items) {
                BigDecimal cur = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                total = total.add(cur);
            }
        }
        return total;
    }


    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
